//
//  ClassA.m
//  MultipleInheritanceDemo
//
//  Created by apple on 2018/1/3.
//  Copyright © 2018年 WJ. All rights reserved.
//

#import "ClassA.h"
#import "ClassB.h"
#import "ClassA+MyCategory.h"

@interface ClassA(){
    ClassB *_b;
}
@end

@implementation ClassA

- (id)init
{
    self = [super init];
    if (self) {
        _b = [[ClassB alloc] init];
        
    }
    return self;
}
- (void)run{
    NSLog(@"跑步");
}
/*- (id)forwardingTargetForSelector:(SEL)aSelector{
 if([_b respondsToSelector:aSelector]){
 return b;
 }
 return nil;
 }*/
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector{
    NSMethodSignature *signature = [super methodSignatureForSelector:aSelector];
    //ClassB *b = [[ClassB alloc] init];
    if(signature == nil){
        signature = [_b methodSignatureForSelector:aSelector];
    }
    NSUInteger argCount = [signature numberOfArguments];
    for (NSInteger i=0; i<argCount; i++) {
          NSLog(@"%s" , [signature getArgumentTypeAtIndex:i]);
    }
    NSLog(@"returnType:%s ,returnLen:%ld" , [signature methodReturnType] , [signature methodReturnLength]);
    NSLog(@"signature:%@" , signature);
    return  signature;
}
- (void)forwardInvocation:(NSInvocation *)anInvocation{
    SEL selector = [anInvocation selector];
    //ClassB *b = [[ClassB alloc] init];
    if([_b respondsToSelector:selector]){
        //这里如果没有响应，系统则会报错崩溃
        [anInvocation invokeWithTarget:_b];
    }
}
@end




